import React from "react";
class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 0,
    };
  }
  state = {
    count: "helloword",
  };
  // 箭头函数
  handleClick = () => {
    this.setState((state) => ({
      count: state.count + 1,
    }));
  };
  //   setState 来自component
  changeInput = (e) => {
    this.setState({
      count: e.target.value,
    });
    console.log(this.state.count);
  };
  //

  render() {
    return (
      <div>
        {/* 如果不修改value的值，写defaultvalue */}
        {/* react 中的change事件是react内部处理后的事件，不管是input/text/select输入后就改变 */}
        <input
          type="text"
          value={this.state.count}
          onChange={this.changeInput}
        />
        <button onClick={this.handleClick}>点击</button>
        {this.state.count}
      </div>
    );
  }
}
export default App;
